package teacher.chapter10;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Example01 {
    public static void main(String[] args) {
        File f = new File("E:\\file\\a.txt");	//使用绝对路径创建File对象
        File f1 = new File("src//Hello.txt");	//使用相对路径创建File对象

        // 创建文件并写入内容
        try {
            // 确保目录存在
            f.getParentFile().mkdirs();

            // 使用 FileWriter 在磁盘上创建并写入文件
            FileWriter writer = new FileWriter(f);
            writer.write("Hello, this is a test file.");
            writer.close();

            FileWriter writer1 = new FileWriter(f1);
            writer1.write("This is a test file.");
            writer1.close();

            System.out.println("Files created: " + f.getAbsolutePath() + " and " + f1.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println(f);
        System.out.println(f1);
    }
}